import request from '@/router/axios'

export function fetchList(query) {
  return request({
    url: '/pvm/arcImage/page',
    method: 'get',
    params: query
  })
}

export function delPictureObj(id) {
  return request({
    url: '/pvm/arcImage/' + id,
    method: 'delete'
  })
}

export function uploadFile(obj,str) {
  return request({
    url: '/pvm/arcImage/uploadFile',
    method: 'post',
    data: obj,str
  })
}
export function getArgImagelst(id) {
  return request({
    url: '/pvm/arcImage/getArgImagelst/'+ id,
    method: 'get',
  })
}


export function getImage(id,imgData) {
  return request({
    url: '/pvm/arcImage/getImage/'+ id,
    method: 'get',
    responseType: 'arraybuffer'
  }).then(response => {
    //将从后台获取的图片流进行转换
    return 'data:image/png;base64,' + btoa(
      new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
    )
  }).then(function(data) {
    //接收转换后的Base64图片
    imgData.src = data
    return data
  }).catch(function(err) {
    console.log(err)
  })
}

//根据服务器上文件名删除数据库对应记录
export function delPictureByFileName(fileName) {
  return request({
    url: '/pvm/arcImage/delete/' + fileName,
    method: 'delete'
  })
}


export function getArgImagelstByDocId(docId) {
  return request({
    url: '/pvm/arcImage/getImageInfoByDocId/'+ docId,
    method: 'get',
  })
}

export function getImagesByPerson(personId,checkDate) {
  return request({
    url: '/pvm/arcImage/getImgList/'+ personId+'/'+checkDate,
    method: 'get',
  })
}
